var grid;
var opeForm;
var cerName;

$(function() {
	opeForm = $('#opeForm');
	// $('input[type="button"]').button();

	grid = $('#gridTable').jqGrid({
		caption : "Certificate List",
		datatype : "local",
		height : 250,
		width : 600,
		colModel : [ {
			name : 'CER_NAME',
			label : 'Certificate name',
			width : 400,
			align : "center"
		} ],
		multiselect : false
	});

	for ( var i = 0; i <= rows.length; i++) {
		$('#gridTable').jqGrid('addRowData', i + 1, rows[i]);
	}
	
	$( "#confirm_password_win" ).dialog({
		autoOpen: false,
		height: 300,
		width: 350,
		modal: true,
		buttons: {
			"OK": confirmPassword,
			Cancel: function() {
				$( this ).dialog( "close" );
			}
		},
		close: function() {
			allFields.val( "" ).removeClass( "ui-state-error" );
		}
	});
	
	$('#okBtn').click(showInputPwdWin);
	$('#cancelBtn').click(closeWin);
});

function showInputPwdWin() {
	var id = $('#gridTable').jqGrid('getGridParam', 'selrow');
	if (id == null) {
		alert('Please select a record!');
		return;
	}
	
	var row = $('#gridTable').jqGrid('getRowData', id);
	cerName = row.CER_NAME;
	
	$( "#confirm_password_win" ).dialog( "open" );
}

function confirmPassword() {
	var options = {
			url : 'BD_USER_REG!doConfirmPassword.do',
			type : 'post',
			data: {'model.CER_NAME' : cerName},
			success : function(data) {
				parent.afterSave();
				alert('Your application is in progress!');
				$( this ).dialog( "close" );
				closeWin();
			}
		};
		
		opeForm.ajaxSubmit(options);
}
